<template>
  <el-dialog
    title="提示！"
    :visible.sync="dialogVisible"
    width="450px"
    :before-close="handleClose"
  >
    <div class="dataBox">
      检测到当前<span
        class="span1"
        :class="inNoticeTime == 1 ? 'span1' : 'span2'"
        >{{ inNoticeTime == 1 ? "正" : "不" }}处于</span
      >启用时间段内是否需要<span
        class="span1"
        :class="status == 0 ? 'span1' : 'span2'"
        >立刻{{ status == 0 ? "启" : "停" }}用</span
      >本功能？
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button class="span5" @click="dialogVisible = false">否</el-button>
      <el-button
        :class="status == 0 ? 'span4' : 'span3'"
        @click="dataFormSubmit"
        >是，{{ status == 0 ? "启" : "停" }}用</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import moment from "moment";
export default {
  data() {
    return {
      items: {},
      status: 0,
      id: "",
      dialogVisible: false,
      dataForm: {
        name: "",
        startTime: "",
        endTime: "",
      },
      s: "",
      e: "",
      inNoticeTime: null,
    };
  },
  methods: {
    open(item, id) {
      console.log(item);
      this.items = item;
      this.id = id;
      this.status = item.status;
      this.dialogVisible = true;
      this.s = moment().format("YYYY-MM-DD") + " " + this.items.startTime;
      this.e = moment().format("YYYY-MM-DD") + " " + this.items.endTime;
      this.inNoticeTime = moment().isBetween(this.s, this.e);
    },
    dataFormSubmit() {
      this.$http({
        url: this.$http.adornUrl(`/platform/noticeNew/updateNoticeNew`),
        method: "post",
        data: {
          ...this.items,
          immediate: 1,
          status: this.items.status == 0 ? 1 : 0,
          id: this.id,
        },
      })
        .then((res) => {
          this.dialogVisible = false;
          this.$message({
            message: res.msg,
            type: "success",
            duration: 1500,
          });
          this.$parent.getDataList();
        })
        .catch((e) => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.dataBox {
  font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
  font-weight: 400;
  font-size: 18px;
  color: #333333;
  padding: 0 40px;
  box-sizing: border-box;
  text-indent: 20px;
  line-height: 30px;
  .span1 {
    color: #1890ff;
  }
  .span2 {
    color: #a2170b;
  }
}
::v-deep .span3 {
  background: #a2170b !important;
  border-radius: 10px 10px 10px 10px;
}
::v-deep .span4 {
  background: #1890ff !important;
  border-radius: 10px 10px 10px 10px;
}
.el-button {
  color: #fff;
}
.span5 {
  width: 80px;
  background: rgba(144, 140, 140, 0.8);
  border-radius: 10px 10px 10px 10px;
}
</style>
